import type { Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { ConfigSvgIconsPlugin } from './svgIcons'
import { AutoRegisterComponents } from './component'
import { ConfigCompressPlugin } from './compress'
import { ConfigPagesPlugin } from './pages'
// import { ConfigVisualizerConfig } from './visualizer'
import { AutoImportDeps } from './autoImport'
import { ConfigMockPlugin } from './mock'
import { ConfigRestartPlugin } from './restart'
import { ConfigLegacyPlugin } from './legacy'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
import commonjs  from '@rollup/plugin-commonjs'

export function createVitePlugins(isBuild: boolean) {
  const vitePlugins: (Plugin | Plugin[])[] = [
    // vue support
    vue(),
    // JSX support
    vueJsx(),
    // Automatically import components on demand Custom components do not take effect
    AutoRegisterComponents(),
    // Automatic route generation function is invalid
    ConfigPagesPlugin(),
    // Automatically import dependencies on demand
    AutoImportDeps(),
    // Enable .gz compression
    ConfigCompressPlugin(),
    // Listen for configuration file changes and restart
    ConfigRestartPlugin(),
    ConfigLegacyPlugin(),
    viteCommonjs(),
    commonjs() as any,
  ]

  vitePlugins.push(ConfigSvgIconsPlugin(isBuild))

  vitePlugins.push(ConfigMockPlugin(isBuild))

  // Package dependency analysis
  // vitePlugins.push(ConfigVisualizerConfig())

  return vitePlugins
}
